package com.iot08.api.utils;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.TimeZone;

public class TimeUtils {
    public static boolean compareHourMin(String hm1, String hm2) {
        LocalTime t1 = LocalTime.parse(hm1);
        LocalTime t2 = LocalTime.parse(hm2);
        return t1.isBefore(t2);
    }

    /**
     * @description 检查当前时间是否处于m点和n点之间
     * @author cwj
     * @param []
     * @return boolean
     * @date @time 2025/6/4 15:13
     **/
    public static boolean isBetweenMAndN(int m,int n) {
        if(m < 0 || n > 23 || n < 0 || m > n) {
            return false;
        }
        LocalTime now = LocalTime.now();
        LocalTime start = LocalTime.of(m, 0);
        LocalTime end = LocalTime.of(n, 0);
        return !now.isBefore(start) && now.isBefore(end);
    }

    /**
     * @description 将YYYY-MM-DD HH:mm:ss的时间格式的字符串转成MM-DD HH:mm时间格式的字符串
     * @author cwj
     * @param [timeStr]
     * @return java.lang.String
     * @date @time 2025/7/8 16:06
     **/
    public static String transferTimeStr(String timeStr){
        String[] timeStrs = timeStr.split(" ");
        String[] dates = timeStrs[0].split("-");
        String[] times = timeStrs[1].split(":");
        StringBuilder stringBuilder = new StringBuilder();
        for(int i=1;i<dates.length;i++) {
            if(i<dates.length-1) {
                stringBuilder.append(dates[i]).append("-");
            } else {
                stringBuilder.append(dates[i]).append(" ");
            }
        }
        for(int i=0;i<times.length-1;i++){
            if(i<times.length-2) {
                stringBuilder.append(times[i]).append(":");
            }else {
                stringBuilder.append(times[i]);
            }
        }
        return stringBuilder.toString();
    }

    /*public static void  main(String[] args){
        System.out.println("JVM Default TimeZone: " + TimeZone.getDefault().getID());
        System.out.println("System ZoneId: " + ZoneId.systemDefault());
        System.out.println("Date: " + new Date());
    }*/

   /* public static void main(String[] args) {
        if (isBetweenMAndN(6,10)) {
            System.out.println("当前时间在 6 点到 10 点之间");
        } else {
            System.out.println("当前时间不在这个范围内");
        }
    }*/
}
